//
//  StudyLinkTableViewCell.m
//  LovingPartyBuilding
//
//  Created by 刘应平 on 17/5/3.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "StudyRankingTableViewCell.h"


@interface StudyRankingTableViewCell ()
/**  头像  */
@property (strong, nonatomic) UIImageView  *headImageView;
/**  名字  */
@property (strong, nonatomic) UILabel  *nameLabel;
/**  排名  */
@property (strong, nonatomic) UILabel  *rankLabel;
/**  时长  */
@property (strong, nonatomic) UILabel  *timeLabel;

/**  下滑线  */
@property (strong, nonatomic) UIView *under ;

@end
/**  55  */
@implementation StudyRankingTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutUI];
        
        self.under  = [UIView new];
        self.under.backgroundColor = [UIColor themeGrayColor];
        [self addSubview:self.under];
        self.under.sd_layout.leftEqualToView(self).bottomEqualToView(self).widthIs([UIScreen zj_screenWith]).heightIs(1);
    }
    return self;
}




#pragma mark - 界面
- (void)layoutUI{
    [self addSubview:self.headImageView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.rankLabel];
    [self addSubview:self.timeLabel];
    
    self.headImageView.sd_layout
    .leftSpaceToView(self, 15 *  [UIScreen zj_screenWScale])
    .heightIs(40 * [UIScreen zj_screenHScale])
    .widthIs(40 * [UIScreen zj_screenHScale])
    .topSpaceToView(self,7.5 * [UIScreen zj_screenHScale]);
    
    self.nameLabel.sd_layout
    .topSpaceToView(self,20 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self.headImageView,15 * [UIScreen zj_screenWScale])
    .heightIs(15 * [UIScreen zj_screenHScale])
    .widthIs(80 * [UIScreen zj_screenWScale]);
    
    
    self.rankLabel.sd_layout
    .topEqualToView(self.nameLabel)
    .leftSpaceToView(self.nameLabel,5 * [UIScreen zj_screenWScale])
    .heightIs(15 * [UIScreen zj_screenHScale])
    .widthIs(50 * [UIScreen zj_screenWScale]);
    
    
    self.timeLabel.sd_layout
    .topEqualToView(self.nameLabel)
    .rightSpaceToView(self,15 * [UIScreen zj_screenWScale])
    .heightIs(15 * [UIScreen zj_screenHScale])
    .widthIs(180 * [UIScreen zj_screenWScale]);
    
}


- (void)setModel:(LpRankingPersonModel *)model{
    _model = model;
    self.nameLabel.text = model.USER_NAME;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,model.PHOTO_URL]] placeholderImage:PlaceholderHeaderImage];
    
    if (self.section != 0) {
        if (self.row < 3) {
            self.rankLabel.textColor = [UIColor zj_colorWithHexString:@"f24141"];
            self.timeLabel.textColor = [UIColor zj_colorWithHexString:@"f24141"];
        }
        self.rankLabel.text = [NSString stringWithFormat:@"第%@名",model.ORDERBY];
        self.timeLabel.text = [NSString stringWithFormat:@"学习时长%@分钟",model.STUDYTIME];
    }else{
        self.under.sd_layout.heightIs(10 * [UIScreen zj_screenHScale]);
        [self.under updateLayout];
        self.rankLabel.text = [NSString stringWithFormat:@"第%@名",model.ORDERBY];
        self.timeLabel.text = [NSString stringWithFormat:@"学习时长%@分钟",model.STUDYTIME];
    }
    
}



#pragma mark - getter
- (UIImageView *)headImageView{
    if (!_headImageView) {
        _headImageView = [UIImageView new];
        _headImageView.layer.cornerRadius = 20 * [UIScreen zj_screenHScale];
        _headImageView.layer.masksToBounds = YES;
    }
    return _headImageView;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _nameLabel;
}



- (UILabel *)rankLabel{
    if (!_rankLabel) {
        _rankLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _rankLabel;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentRight;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _timeLabel;
}



@end
